home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / hardware / cpu115 / model486.asm < prev    next >
Encoding:
Assembly Source File  |  1995-02-27  |  3.1 KB  |  103 lines

  1. ; -----------------------------------------------------------------------------
  2. ; MODEL486.ASM    Code to determine 486 chip step and model without using
  3. ;        CPUID instruction (requires processor to be in real mode).
  4. ;
  5. ; Copyright(c) by Ilya Tumanov of 2:5030/82.6@fidonet
  6. ; Included in TMi0SDGL by the author's permission.
  7. ; -----------------------------------------------------------------------------
  8. ;
  9. ; The following code uses CPU reset sequence to obtain CPU internal ID.
  10. ; Thus it won't work from protected mode and on some BIOSes it may return
  11. ; incorrect results if the BIOS code destroys registers during initialization
  12. ; before passing control back to our code (Award BIOS is known to do so, while
  13. ; AMI and MR returns needed register unchanged).
  14. ;
  15. ; Returned code is (afaik) formatted like this:
  16. ;
  17. ; bits 15-12: reserved
  18. ;  bits 11-8: CPU family ( 3 for 386, 4 for 486, 5 for P5, etc.)
  19. ;   bits 7-4: CPU model  ( see table below )
  20. ;   bits 3-0: CPU step/submodel
  21. ;
  22. ; CPU models defined for now (this list maybe not complete):
  23. ;
  24. ; 0,1: DX
  25. ; 2  : SX
  26. ; 3  : DX2/Overdrive
  27. ; 4  : SL
  28. ; 5  : SX2
  29. ; 7  : P24D (Pentium Overdrive)
  30. ; 8  : DX4
  31. ;
  32. ; other codes are currently undefined (that is, reserved). These codes are
  33. ; also partially valid for 386 CPUs (excluding DX2, SX2 and DX4).
  34. ;
  35. ; Note that the table is valid only for Intel/AMD/UMC chips. Cyrix/TI chips
  36. ; also return such info, but its meaning is different.
  37. ;
  38.  
  39.     INCLUDE    HEADER.ASH
  40.  
  41.     .CODE
  42.  
  43.     .286
  44.  
  45.     PUBLIC    get486Model
  46.  
  47. save_sp    dw    ?    ; we'll save SP here
  48. save_bp dw    ?    ; saved BP
  49. save_ss    dw    ?    ; saved SS
  50.  
  51. get486Model    proc
  52. ; all GPRs destroyed, except SP and BP. Segment registers are preserved.
  53.  
  54.     in    al,21h        ; get IRQ mask
  55.     push    ax        ; and save it on stack
  56.     push    ds es        ; DS and ES are saved on stack too
  57.     mov    cs:save_sp,sp    ; save stack offset
  58.     mov    cs:save_ss,ss    ; and segment
  59.     mov    cs:save_bp,bp    ; save BP for the case it gets corrupted
  60.     push    0040h        ; segment addr of BIOS RAM work area
  61.     pop    es        ; put in es
  62.     mov    ax,offset quit    ; get return addr offset after reset
  63.     mov    es:[67h],ax    ; put in return address area in BIOS RAM
  64.     mov    ax,cs        ; get our current code segment
  65.     mov    es:[69h],ax    ; put in return address area in BIOS RAM
  66.  
  67.     mov    al,08Fh        ; address of CMOS RAM to use  (8FH)
  68.     out    70h,al        ; set CMOS RAM address latch
  69.     REPT    3
  70.     db    0EBh,00h    ; jmp short $+2
  71.     ENDM
  72.     mov    al,5        ; signal that this reset is a return
  73.     out    71h,al        ; from protected mode-output to CMOS RAM
  74.     REPT    3
  75.     db    0EBh,00h    ; jmp short $+2
  76.     ENDM
  77.     mov    al,0FEh        ; load shutdown command for the 8042
  78.     out    64h,al        ; issue the reset
  79.     hlt            ; halt while waiting for hardware reset
  80.     db    0EBh,-3        ; jmp short $-1 in case of interrupt
  81.  
  82. quit:
  83.  
  84. ; processor reset at this point, interrupts are disabled and IRQs masked.
  85. ; restoring segment registers.
  86.  
  87.     mov    sp,cs:save_ss    ; restoring stack first of all
  88.     mov    ss,sp
  89.     mov    sp,cs:save_sp
  90.     mov    bp,cs:save_bp
  91.     pop    es ds        ; then restoring segment registers
  92.     pop    ax        ; al = saved IRQ mask
  93.     out    21h,al        ; restore IRQ mask
  94.  
  95.     sti            ; reenable interrupts
  96.  
  97.     mov    ax,dx        ; DX contains the same code as returned in
  98.                 ; AX by CPUID with EAX=1
  99.     ret
  100.     endp
  101.  
  102.     END
  103.